/**
 * 
 */
package de.oszimtcc.timetablehelper;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import de.oszimtcc.timetablecore.Timetable;


/**
 * @author reuter
 *
 */
public class ObjectSerializator
{
	public static byte[] SerializeTimetable(Timetable pTimetable)
	{
	    ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
	    
	    try 
	    { 
	      ObjectOutput out = new ObjectOutputStream(bos); 
	      out.writeObject(pTimetable); 
	      out.close(); 
	      
	      return bos.toByteArray(); 
	    } 
	    catch(IOException ioe) 
	    { 
	      return null;
	    } 
	}
	
	 public static Timetable DeserializeTimetable(byte[] pStoredObject) 
	 { 
		try 
		{ 
		  ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(pStoredObject)); 
		  Timetable timetable = (Timetable)in.readObject(); 
		  in.close(); 
		
		  return timetable; 
		} 
		catch(ClassNotFoundException cnfe)
		{ 
		  return null; 
		} 
		catch(IOException ioe) 
		{   
		  return null; 
		} 
	} 
}
